﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>简单聊天系统登录</title>

<link type="text/css" href="res/css/login.css" rel="stylesheet" />
	<script crossorigin="anonymous" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>

</head>
<body>

<div class="login">

	<h1>会员登录</h1>
	
	<input type="text" id="userAccount" name="u" placeholder="用户名" required="required" />
	<input type="password" id="userPassword" name="p" placeholder="密码" required="required" />
	<button type="submit" id="button" class="btn btn-primary btn-block btn-large">登录</button>

</div> 

</body>
</html>
<script>

	$(() => {
		$("#button").on("click", () => {
			var data = {
				action: "login",
				userAccount: $("#userAccount").val(),
				userPassword: $("#userPassword").val()
			}
			$.post("LoginServlet", data, (object) => {
				if (object.state == 1) {
					window.location.href = "chat.html";
				} else {
					alert(object.message);
				}
			}, "json")
		})
	})
</script>
